<template>
  <div class="login-panel">
    <h1 class="title">欢迎注册中酒云网</h1>
    <div class="tabs">
      <div class="top">
        <el-form-item label="选择注册类型" :label-width="150">
          <el-row justify="space-between" align="bottom">
            <el-col :span="11">
              <el-button
                plain
                class="primaryBtn"
                :class="{ activeBtn: activeName == 'unit' }"
                size="large"
                @click="changeType('unit')"
              >
                单位注册
              </el-button>
            </el-col>
            <el-col :span="11">
              <el-button
                plain
                class="primaryBtn"
                :class="{ activeBtn: activeName == 'account' }"
                size="large"
                @click="changeType('account')"
              >
                个人注册
              </el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </div>
      <div>
        <panel-unit v-if="activeName == 'unit'" ref="unitRef" v-model:loading="loading" />
        <panel-account
          v-if="activeName == 'account'"
          ref="accountRef"
          v-model:loading="loading"
        />
      </div>
    </div>
    <div class="tips">
      登录注册即视为同意<i style="color: #4098ff; cursor: pointer">
        <span @click="handleAgreement('USER_AGREEMENT')">《中酒云网服务条款》</span
        ><span @click="handleAgreement('PRIVACY_AGREEMENT')">《隐私政策》</span>
      </i>
    </div>
    <el-row justify="space-between" align="bottom" :gutter="20">
      <el-col :span="12">
        <el-button class="login-btn1" type="primary" size="large" @click="returnLogin()">
          返回登录
        </el-button>
      </el-col>
      <el-col :span="12">
        <el-button
          class="login-btn"
          type="primary"
          size="large"
          @click="handleRegister()"
          :loading="loading"
        >
          立即注册
        </el-button>
      </el-col>
    </el-row>
    <Agreement-modal v-model:show="agreementShow" :type="type" btn-text="确 定" />
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import PanelUnit from "./PanelUnit.vue"; // 单位注册
import PanelAccount from "./PanelAccount.vue"; // 个人注册
import router from "@/router";

const loading = ref(false); // 防止重复点击
const activeName = ref("unit"); // 当前选项卡
const agreementShow = ref(false); // 协议弹窗
const accountRef = ref();
const unitRef = ref();
const type = ref("USER_AGREEMENT");

// 切换选项卡
const changeType = (e: any) => {
  activeName.value = e;
};

//返回登录
const returnLogin = () => {
  router.push("/login");
};

// 注册
const handleRegister = () => {
  if (activeName.value == "unit") {
    unitRef?.value.getLoginAction();
  } else {
    accountRef?.value.loginAction();
  }
};

// 打开协议弹窗
const handleAgreement = (e: any) => {
  type.value = e;
  agreementShow.value = true;
};
</script>

<style lang="less" scoped>
.login-panel {
  width: 750px;
  padding: 20px 100px;
  background: rgba(255, 255, 255, 0.8);
  .top {
    .el-row {
      width: 100%;
      .el-button {
        width: 100%;
      }
      .primaryBtn {
        width: 100%;
        border-radius: 5px;
        border: 1px solid #d9d9d9;
        color: #b2b2b2;
        background: rgba(255, 255, 255, 0.3);
      }
      .activeBtn {
        width: 100%;
        color: #4098ff;
        border-radius: 5px;
        border: 1px solid #4098ff;
        background: rgba(64, 152, 255, 0.1);
        box-shadow: 0px 0px 0px 1px rgba(64, 152, 255, 0.2);
      }
    }
  }
  .title {
    text-align: center;
    margin-bottom: 15px;
  }
  .icon {
    display: flex;
    align-items: center;
    justify-content: center;
    .text {
      margin-left: 5px;
    }
  }
  .controls {
    display: flex;
    margin-top: 12px;
    justify-content: space-between;
  }
  .login-btn {
    margin-top: 10px;
    width: 100%;
  }
  .login-btn1 {
    border: 0.5px solid #4098ff;
    background: #fff;
    width: 100%;
    color: #4098ff;
  }
  .tips {
    margin: 20px;
    text-align: center;
    color: #b2b2b2;
  }
}
</style>
